<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="操作类型">
              <j-dict-select-tag placeholder="请选择操作类型" v-model="queryParam.goldActionType" dictCode="gold_action_type"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="订单号">
              <a-input placeholder="请输入订单号" v-model="queryParam.orderCodeNum"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="成色">
                <j-search-select-tag placeholder="请选择成色" v-model="queryParam.karat" dict="gold_karat,gold_karat_name,id"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="种类">
                <j-dict-select-tag placeholder="请选择种类" v-model="queryParam.cate" dictCode="gold_type"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button> -->
      <a-button type="primary" icon="usergroup-add" v-has="'goldEntry:outin'" @click="opsByStep" >批量出入库操作</a-button>

    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" v-has="'goldEntry:edit'">修改</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item v-has="'goldEntry:delete'">
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <gold-entry-modal ref="modalForm" @ok="modalFormOk"></gold-entry-modal>
    <step-modal ref="stepForm" @ok="loadData(1)"></step-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import GoldEntryModal from './modules/GoldEntryModal'
import StepModal from './modules/StepModal'

export default {
  name: 'GoldEntryList',
  mixins:[JeecgListMixin, mixinDevice],
  components: {
    GoldEntryModal, StepModal
  },
  data () {
    return {
      description: ' 金出入库管理页面',
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key:'rowIndex',
          width:40,
          align:"center",
          customRender:function (t,r,index) {
            return parseInt(index)+1;
          }
        },
        {
          title:'类型',
          align:"center",
          sorter: true,
          dataIndex: 'goldActionType_dictText'
        },
        {
          title:'订单号',
          align:"center",
          sorter: true,
          dataIndex: 'orderCodeNum'
        },
        {
          title:'工单号',
          align:"center",
          dataIndex: 'workNum'
        },
        {
          title:'拆分页',
          align:"center",
          sorter: true,
          dataIndex: 'pn'
        },
        {
          title:'发出方',
          align:"center",
          sorter: true,
          dataIndex: 'senderName'
        },
        {
          title:'发出时间',
          align:"center",
          dataIndex: 'sendTime',
          customRender:function (text) {
            return !text?"":(text.length>10?text.substr(0,10):text)
          }
        },
        {
          title:'接收方',
          align:"center",
          dataIndex: 'receiverName'
        },
        {
          title:'接收时间',
          align:"center",
          dataIndex: 'receiveTime',
          customRender:function (text) {
            return !text?"":(text.length>10?text.substr(0,10):text)
          }
        },
        {
          title:'款号',
          align:"center",
          dataIndex: 'styleCodeNum'
        },
        {
          title:'成色',
          align:"center",
          sorter: true,
          dataIndex: 'karat_dictText'
        },
        {
          title:'来料名称',
          align:"center",
          dataIndex: 'name'
        },
        {
          title:'种类',
          align:"center",
          dataIndex: 'cate_dictText'
        },
        {
          title:'规格',
          align:"center",
          dataIndex: 'style'
        },
        {
          title:'数量',
          align:"center",
          dataIndex: 'count'
        },
        {
          title:'连石重',
          align:"center",
          dataIndex: 'withStoneWeight'
        },
        {
          title:'石重(ct)',
          align:"center",
          dataIndex: 'pureStoneWeight'
        },
        {
          title:'净重',
          align:"center",
          dataIndex: 'goldWeight'
        },
        {
          title:'单价(￥)',
          align:"center",
          dataIndex: 'unitPrice'
        },
        {
          title:'价值金额(￥)',
          align:"center",
          dataIndex: 'costAmount'
        },
        {
          title:'实付金额(￥)',
          align:"center",
          dataIndex: 'payAmount'
        },
        {
          title:'耗率(%)',
          align:"center",
          dataIndex: 'attritionRate'
        },
        {
          title:'给耗重',
          align:"center",
          dataIndex: 'giveAttrition'
        },
        {
          title:'不计耗重',
          align:"center",
          dataIndex: 'noAttritionWeight'
        },
        {
          title:'工费',
          align:"center",
          dataIndex: 'procedureUnitPrice'
        },
        {
          title:'折足率(%)',
          align:"center",
          dataIndex: 'goldContent'
        },
        {
          title:'折足重',
          align:"center",
          dataIndex: 'goldContentWeight'
        },
        {
          title:'备注',
          align:"center",
          dataIndex: 'remark'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align:"center",
          fixed:"right",
          width:147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: "/goldEntry/list",
        delete: "/goldEntry/delete",
        deleteBatch: "/goldEntry/deleteBatch",
        exportXlsUrl: "/goldEntry/exportXls",
        importExcelUrl: "/goldEntry/importExcel",
      },
      dictOptions:{},
      superFieldList:[],
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    opsByStep() {
      this.$refs.stepForm.init()
    },
    initDictConfig(){
    },
    getSuperFieldList(){
      let fieldList=[];
      fieldList.push({type:'string',value:'goldActionType',text:'操作类型',dictCode:'gold_action_type'})
      fieldList.push({type:'string',value:'orderCodeNum',text:'订单号',dictCode:'gold_storage,name,id'})
      fieldList.push({type:'string',value:'workNum',text:'工单号',dictCode:'gold_storage,name,id'})
      fieldList.push({type:'sel_search',value:'pn',text:'拆分页',dictTable:'customer_info', dictText:'cus_name', dictCode:'id'})
      fieldList.push({type:'string',value:'styleCodeNum',text:'款号',dictCode:''})
      fieldList.push({type:'sel_search',value:'karat',text:'成色',dictTable:'gold_karat', dictText:'gold_karat_name', dictCode:'id'})
      fieldList.push({type:'string',value:'name',text:'来料名称',dictCode:''})
      fieldList.push({type:'string',value:'cate',text:'种类',dictCode:'gold_type'})
      fieldList.push({type:'string',value:'style',text:'规格',dictCode:''})
      fieldList.push({type:'int',value:'count',text:'数量',dictCode:''})
      fieldList.push({type:'BigDecimal',value:'withStoneWeight',text:'连石重',dictCode:''})
      fieldList.push({type:'BigDecimal',value:'pureStoneWeight',text:'石重(ct)',dictCode:''})
      fieldList.push({type:'string',value:'goldWeight',text:'净重',dictCode:''})
      fieldList.push({type:'BigDecimal',value:'unitPrice',text:'单价(￥)',dictCode:''})
      fieldList.push({type:'BigDecimal',value:'costAmount',text:'价值金额(￥)',dictCode:''})
      fieldList.push({type:'BigDecimal',value:'payAmount',text:'实付金额(￥)',dictCode:''})
      fieldList.push({type:'BigDecimal',value:'attritionRate',text:'耗率(%)',dictCode:''})
      fieldList.push({type:'BigDecimal',value:'giveAttrition',text:'给耗重',dictCode:''})
      fieldList.push({type:'BigDecimal',value:'noAttritionWeight',text:'不计耗重',dictCode:''})
      fieldList.push({type:'BigDecimal',value:'procedureUnitPrice',text:'工费',dictCode:''})
      fieldList.push({type:'BigDecimal',value:'goldContent',text:'折足率(%)',dictCode:''})
      fieldList.push({type:'BigDecimal',value:'goldContentWeight',text:'折足重',dictCode:''})
      fieldList.push({type:'Text',value:'remark',text:'备注',dictCode:''})
      fieldList.push({type:'string',value:'sn',text:'操作流水号',dictCode:''})
      fieldList.push({type:'popup',value:'purchaseOrderNum',text:'采购单号', popup:{code:'gold_purchase_report',field:'purchase_order_num',orgFields:'purchase_order_num',destFields:'purchase_order_num'}})
      fieldList.push({type:'sel_user',value:'sender',text:'发出方'})
      fieldList.push({type:'date',value:'sendTime',text:'发出时间'})
      fieldList.push({type:'sel_user',value:'receiver',text:'接收方'})
      fieldList.push({type:'date',value:'receiveTime',text:'接收时间'})
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>